Release 10.1A: OpenEdge Data Management:
SQL Development
OLDROW and NEWROW objects: passing values to triggers
The
OLDROWandNEWROWobjects allow SQL to pass row values as input parameters to the stored procedure in a trigger that executes once for each affected row. If theCREATE TRIGGERstatement contains theREFERENCINGclause, the SQL server implicitly instantiates anOLDROWorNEWROWobject (or both, depending on the arguments to theREFERENCINGclause) when it creates the Java class.This allows the Java code in the snippet to use the
getValuemethod of those objects to retrieve values of columns in rows affected by the trigger event and store them in procedure variables:
- The
OLDROWobject contains values of a row as it exists in the database before an update or delete operation. It is instantiated when triggers specify anUPDATE...REFERENCINGOLDROWorDELETE...REFERENCING OLDROWclause. It is meaningless and not available for insert operations.- The
NEWROWobject contains values of a row as specified in anINSERTorUPDATEstatement. It is instantiated when triggers specify anUPDATE...REFERENCING NEWROWorINSERT...REFERENCING NEWROWclause. It is meaningless and not available for delete operations.
UPDATEis the only triggering statement that allows bothNEWROWandOLDROWin theREFERENCINGclause.Triggers use the
OLDROW.getValueandNEWROW.getValuemethods to assign a value from a row being modified to a procedure variable. The format and arguments forgetValueare the same as in other OpenEdge SQL Java classes:
col_numSpecifies the integer column number of the affected row.
getValueretrieves the value in the column denoted by col_num.1denotes the first column of the result set,2denotes the second, n denotes the nth.sql_data_typeSpecifies the corresponding SQL data type. For a complete list of appropriate data types, refer to Table 9–2.
Example 9–22 shows an excerpt from a trigger that uses
getValueto assign values from bothOLDROWandNEWROWobjects.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |